<html><head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>领料入库</title>
  <#assign base=request.contextPath  />
    <link rel="stylesheet" href="${base}/js/layui/css/layui.css" media="all">
    <script type="text/javascript" src="${base}/js/zhang.js"></script>
    <style type="text/css" >
        .layui-btn-radius{
            border-radius: 5px;
        }
    </style>
</head>

<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>领料入库</legend>
</fieldset>

<div class="demoTable"style="padding:15px;">
    <button class="layui-btn layui-btn-radius" id="btn2" data-method="offset" type="button" style="background-color: #0092EF;">领料入库</button>
    <div class="layui-inline layui-form" style="float:right;" >
        <div class="layui-input-inline">
            <select name="modules" lay-verify="required"  id="sech" lay-search="">
                <option value="">请选择要搜索的列</option>
                <option value="kind">物品种类</option>
                <option value="itemName">物品名称</option>
                <option value="company">规格</option>
                <option value="unit">单价</option>
                <option value="department">采购单位</option>
                <option value="purchasingAgent">经办人</option>
                <option value="amount">物品数量</option>
                <option value="total">总价</option>
            </select>
        </div>
        <div class="layui-inline">
            <input class="layui-input" name="id" id="demoReload" autocomplete="off">
        </div>
        <button class="layui-btn layui-btn-radius" id="btn1" data-type="reload" style="background-color: #0092EF;">搜索</button>
    </div>
</div>
<table class="layui-hide" id="ckgl"></table>
<script src="${base}/js/jquery.min.js"></script>
<script src="${base}/js/layui/layui.js"></script>
<script>

    layui.use(['form', 'layedit', 'laydate','table'], function(){
        var form = layui.form
                ,$ = layui.jquery
                ,layer = layui.layer
                ,layedit = layui.layedit
                ,laydate = layui.laydate
        table = layui.table;
        table.render({
            elem: '#ckgl'
            ,url: '${base}/picking/selectPicking'//数据接口
            ,toolbar: '#toolbarDemo'
            ,defaultToolbar: ['filter', 'print', 'exports']
            ,cols: [[
                {field:'id', title:'序号',templet:function(val){return val.LAY_INDEX},align:'center', fixed: true}
                ,{field:'kind', title: '物品种类',align:'center'}
                ,{field:'itemName', title: '物品名称',align:'center'}
                ,{field:'company',title: '规格',align:'center'}
                ,{field:'unit',title: '单价',align:'center'}
                ,{field:'department', title: '采购单位',align:'center'}
                ,{field:'purchasingAgent', title: '经办人',align:'center'}
                ,{field:'amount', title: '物品数量', align:'center'}
                ,{field:'total',title: '总价',templet:function(val){
                        return toDecimal2( Number(val.unit)*Number(val.amount))
                    },align:'center'}
                ,{field:'date',title: '日期',align:'center',templet:function(val){
                        return changeDateFormat(val.date);
                    }}
            ]]
            ,id: 'testReload'
            ,height:'600'
            ,page: {
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                ,theme: '#0092EF'
            }   ,done: function(res, curr, count){
                this.where={};
            }
        });

        $('#btn1').on('click', function(){
            var whereData={};
            var sechLin=$("#sech").val();
            if(sechLin=="amount"){
                whereData.amount=Trim($("#demoReload").val());
            }
            if(sechLin=="kind"){
                whereData.kind=Trim($("#demoReload").val());
            }
            if(sechLin=="department"){
                whereData.department=Trim($("#demoReload").val());
            }
            if(sechLin=="purchasingAgent"){
                whereData.purchasingAgent=Trim($("#demoReload").val());
            }
            if(sechLin=="itemName"){
                whereData.itemName=Trim($("#demoReload").val());
            }
            if(sechLin=="unit"){
                whereData.unit=Trim($("#demoReload").val());
            }
            if(sechLin=="total"){
                whereData.total=Trim($("#demoReload").val());
            }
            if(sechLin=="company"){
                whereData.company=Trim($("#demoReload").val());
            }
            whereData.page=1;
            whereData.limit=10;
            var table = layui.table;
            //表刷新方法
            table.reload('testReload', {
                url: '${base}/picking/selectPicking'
                ,where: whereData
            });

        });


        var active = {
            offset: function(othis){
                var type = othis.data('type')
                        ,text = othis.text();
                layer.open({
                    type: 2,
                    title: '领料入库',
                    offset: 't',
                    shadeClose:false ,
                    area:['475','100%'],
                    content: ['${base}/picking/picking_add.html','no']
                });
            }
        };
        $('#btn2').on('click', function(){
            var othis = $(this), method = othis.data('method');
            active[method] ? active[method].call(this, othis) : '';
        });

        layui.form.on('select()', function(data){
            $("#demoReload").val("")
        });

    });

    //键盘事件
    $("body").bind("keydown",function(e){
        // 兼容FF和IE和Opera
        var theEvent = e || window.event;
        var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
        if (code == 13) {
            //回车执行查询
            $("#btn1").click();
        }
    });
    // 总价 强制保留两位小数
    function toDecimal2(x) {
        var f = parseFloat(x);
        if (isNaN(f)) {
            return false;
        }
        var f = Math.round(x*100)/100;
        var s = f.toString();
        var rs = s.indexOf('.');
        if (rs < 0) {
            rs = s.length;
            s += '.';
        }
        while (s.length <= rs + 2) {
            s += '0';
        }
        return s;
    }



</script>

</body>
</html>